﻿<!DOCTYPE html>
<html lang="en">
<head>
    <title id="Description">Column Formatting in jqxDataTable</title>
    <meta name="description" content="This sample demonstrates how we can Format Columns in jQWidgets DataTable.">
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdatatable.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="../../scripts/demos.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var url = "../sampledata/orders.xml";
            // prepare the data
            var source =
            {
                datatype: "xml",
                datafields: [
                    { name: 'ShippedDate', map: 'm\\:properties>d\\:ShippedDate', type: 'date' },
                    { name: 'Freight', map: 'm\\:properties>d\\:Freight', type: 'float' },
                    { name: 'ShipName', map: 'm\\:properties>d\\:ShipName' },
                    { name: 'ShipAddress', map: 'm\\:properties>d\\:ShipAddress' },
                    { name: 'ShipCity', map: 'm\\:properties>d\\:ShipCity' },
                    { name: 'ShipCountry', map: 'm\\:properties>d\\:ShipCountry' }
                ],
                root: "entry",
                record: "content",
                id: 'm\\:properties>d\\:OrderID',
                url: url,
                pager: function (pagenum, pagesize, oldpagenum) {
                    // callback called when a page or page size is changed.
                }
            };
            var dataAdapter = new $.jqx.dataAdapter(source);

            $("#dataTable").jqxDataTable(
            {
                width: 850,
                source: dataAdapter,
                sortable: true,
                pageable: true,
                columnsResize: true,
                columns: [
                  { text: 'Shipped Date', datafield: 'ShippedDate', width: '50%', cellsFormat: 'D' },
                  { text: 'Freight', datafield: 'Freight', width: '50%', cellsFormat: 'F2', cellsalign: 'right' }
                ]
            });

            $("#dateFormats").jqxDropDownList({selectedIndex: 1, autoDropDownHeight: true, source: ['Short Date', 'Long Date', 'Long date, Short Time', 'Long date, Long Time', 'Month/Year', 'Month/Day', 'Custom'], height: 25 });
            $("#dateFormats").on('change', function (event) {
                var index = event.args.index;
                switch (index) {
                    case 0:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'cellsFormat', 'd');
                        break;
                    case 1:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'cellsFormat', 'D');
                        break;
                    case 2:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'cellsFormat', 'f');
                        break;
                    case 3:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'cellsFormat', 'F');
                        break;
                    case 4:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'cellsFormat', 'Y');
                        break;
                    case 5:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'cellsFormat', 'M');
                        break;
                    case 6:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'cellsFormat', 'yyyy-MM-dd HH:mm:ss');
                        break;
                }
            });
            $("#numberFormats").jqxDropDownList({ selectedIndex: 1, autoDropDownHeight: true, source: ['n', 'f', 'f2', 'f3', 'c', 'c2', 'c3', 'p', 'p2', 'p3'], height: 25 });
            $("#numberFormats").on('change', function (event) {
                var index = event.args.index;
                switch (index) {
                    case 0:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsFormat', 'n');
                        break;
                    case 1:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsFormat', 'f');
                        break;
                    case 2:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsFormat', 'f2');
                        break;
                    case 3:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsFormat', 'f3');
                        break;
                    case 4:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsFormat', 'c');
                        break;
                    case 5:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsFormat', 'c2');
                        break;
                    case 6:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsFormat', 'c3');
                        break;
                    case 7:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsFormat', 'p');
                        break;
                    case 8:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsFormat', 'p2');
                        break;
                    case 9:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsFormat', 'p3');
                        break;
                }
            });
        });
    </script>
</head>
<body class='default'>
    <div id="dataTable">
    </div>
    <div style="font-size: 13px; font-family: Verdana; width: 600px; margin-top: 10px;">
        <div style="float: left; width: 300px;">
            <h4>Shipped Date</h4>
            <div id="dateFormats"></div>
        </div>
        <div style="float: left; width: 300px;">
            <h4>Freight</h4>
            <div id="numberFormats"></div>
        </div>
    </div>
</body>
</html>
